var g_index = 0

function Update() 
{
	var prefs = new gadgets.Prefs();
  
  var quotes = prefs.getArray("quotes");
	var nextIndex = 0
	
	if( quotes != null && quotes.length > 1 ) {
		nextIndex = Math.round( Math.random() * (quotes.length - 1) );
		if( nextIndex == g_index )
			nextIndex = (g_index + 1) % quotes.length;
	}

	g_index = nextIndex;
   				  
	var text = "";
	if( quotes != null && quotes.length > 0 ) {
		var t = (quotes[ g_index ]);
		text = "Q[" + g_index + "]: " + t;
	} else {
		text = "Please, enter some new quoutes!";
	}

	document.getElementById("content_div").innerHTML = text;

	gadgets.window.adjustHeight();
}

function Initialize()
{
		backgroundColor = gadgets.skins.getProperty('CONTENT_BG_COLOR');
		document.body.style.backgroundColor = backgroundColor;

	  textColor = gadgets.skins.getProperty('CONTENT_TEXT_COLOR');
    document.getElementById("content_div").style.color = textColor;

		Update();
}

gadgets.util.registerOnLoadHandler(Initialize);
